package cmdb

import (
	"errors"
	"k8s-platform/dao"
	"k8s-platform/model"
)

var HostGroup hostgroup

type hostgroup struct{}

// 列表
func (*hostgroup) List() ([]*model.HostGroup, error) {
	return dao.HostGroup.List()
}

// 查询单个
func (*hostgroup) Has(hostgroup string) (*model.HostGroup, bool, error) {
	return dao.HostGroup.Has(hostgroup)
}

// 查询单个
func (*hostgroup) Get(id int64) (*model.HostGroup, bool, error) {
	return dao.HostGroup.Get(id)
}

// 新增
func (*hostgroup) Add(hostgroup *model.HostGroup) error {
	_, has, err := dao.HostGroup.Has(hostgroup.GroupName)
	if err != nil {
		return err
	}
	if has {
		return errors.New("该数据已存在，请重新添加")
	}

	if err := dao.HostGroup.Add(hostgroup); err != nil {
		return err
	}
	return nil
}

// 更新
func (*hostgroup) Update(hostgroup *model.HostGroup) error {
	return dao.HostGroup.Update(hostgroup)
}

// 删除
func (*hostgroup) Delete(hostgroup *model.HostGroup, id int64) error {
	return dao.HostGroup.Delete(hostgroup, id)
}
